<template>
  <a-drawer
    :maskClosable="false"
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
    <erp-finance-project-progress-payment-application-bill-form ref="realForm" @ok="submitCallback" @unButtonDisable="unButtonDisable" :disabled="disableSubmit" normal></erp-finance-project-progress-payment-application-bill-form>
    <div class="drawer-footer">
      <CommonDrawerFooterButton
        startProcess="erpFinanceProjectProgressPaymentApplicationBill: startProcess"
        :disableSubmit="disableSubmit"
        :buttonDisable="buttonDisable"
        @handleCancel="handleCancel"
        @handleOk="handleOk"
        @beginProcess="beginProcess"
      ></CommonDrawerFooterButton>
    </div>
  </a-drawer>
</template>

<script>

  import ErpFinanceProjectProgressPaymentApplicationBillForm from './ErpFinanceProjectProgressPaymentApplicationBillForm'
  import { getAction } from '@/api/manage'
  import CommonDrawerFooterButton from '@/views/components/CommonDrawerFooterButton.vue';
  import { ModalClickMixin } from '@/mixins/ModalClickMixin'
  export default {
    name: 'ErpFinanceProjectProgressPaymentApplicationBillModal',
    components: {
      ErpFinanceProjectProgressPaymentApplicationBillForm,
      CommonDrawerFooterButton
    },
    mixins: [ModalClickMixin],
    data () {
      return {
        url: {
          queryOwnerById: '/api/erp/finance/projectProgress/erpFinanceProjectOwnerInfo/queryByBillId',
          queryConstructById: '/api/erp/finance/projectProgress/erpFinanceProjectConstructionPartyInfo/queryByBillId'
        }
      }
    },
    methods: {
      add () {
        this.buttonDisable = false
        this.visible = true
        this.$nextTick(() => {
          this.$refs.realForm.add();
        })
      },
      async edit (record, flag) {
        this.buttonDisable = false
        this.visible = true
        if (flag) {
          record.ownerInfo = await this.getChildData(this.url.queryOwnerById, { billId: record.id });
          record.constructInfo = await this.getChildData(this.url.queryConstructById, { billId: record.id });
        }
        this.$nextTick(() => {
          this.$refs.realForm.edit(record);
        });
      },
      // 获取子表数据
      getChildData(url, param) {
        return new Promise((resolve) => {
          getAction(url, param).then((res) => {
            if (res.success) {
              let data = res.result;
              resolve(data);
            }
          })
        })
      }
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
  .drawer-footer{
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
    z-index: 100;
  }
</style>
